﻿using Nop.Core.Domain.Common;
using System;

namespace Nop.Core.Domain.Logistics
{
    public class LogisticsLocation : BaseEntity
    {
        #region Properties

        public virtual int AddressId { get; set; }

        public virtual int? PackageId { get; set; }

        public virtual int? PlanId { get; set; }

        public virtual int? CourierId { get; set; }

        public DateTime? UpdatedOnUtc { get; set; }
        
        public DateTime CreatedOnUtc { get; set; }

        public int? Rank { get; set; }

        public LocationStatus Status { get; set; }

        public virtual int? DistrictId { get; set; }

        #endregion

        #region Navigation properties

        public virtual Address Address { get; set; }

        public virtual LogisticsPlan Plan { get; set; }

        public virtual LogisticsCourier Courier { get; set; }

        public virtual LogisticsPackage Package { get; set; }

        public virtual District District { get; set; }

        #endregion

        #region Utilities

        public LogisticsLocation RelatedLocation
        {
            get
            {
                if (Package == null)
                {
                    return null;
                }
                if (Status == LocationStatus.PendingDropOff || Status == LocationStatus.ReadyForDropOff)
                {
                    return Package.PickUpLocation;
                }
                else if (Status == LocationStatus.ReadyForPickUp)
                {
                    return Package.DeliveryLocation;
                }

                return null;
            }
        }

        #endregion
    }

    public enum LocationStatus : byte
    {
        Unknown,
        ReadyForPickUp,
        PendingDropOff,
        ReadyForDropOff,
        Complete
    }
}
